package com.xjtu.chapter03;

/**
 * @author yjq
 * @version 1.0
 * @date 2021/8/11 21:37
 */
public class Ex3_StringBufferTest {
    //测试StringBuffer类，实现字符串的内容替换、反转等功能
    public static void main(String[] args) {
        String str1 = "Welcome to Java";
        StringBuffer sf1 = new StringBuffer();
        sf1.append(str1);
        System.out.println("字符串sf1为："+sf1);
        System.out.println("字符串sf1的长度为："+sf1.length());
        System.out.println("字符串sf1的容量为: "+sf1.capacity());
        sf1.setCharAt(2,'E');//更改字符串中的字母
        System.out.println("修改以后的字符串为："+sf1);

        sf1.reverse();
        System.out.println("倒转以后的字符串为："+sf1);

        sf1.replace(0,5,"hello");
        System.out.println("用hello替代以后的字符串为："+sf1);
    }
}
